#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	vector<string> datas;
	string cur;
	while (cin >> cur) {
		datas.push_back(cur);
	}
	string tgt = datas.back();
	cin >> tgt;
	int l = -1, r = datas.size();
	while (l < r) {
		do l++; while (datas[l] != tgt);
		do r--; while (datas[r] == tgt);
		if (l < r) swap(datas[l], datas[r]);
	}
	datas.resize(l);
	cout << datas.size() << endl;
	for (int i = 0; i < datas.size(); ++i) {
		if (i) cout << ",";
		cout << datas[i];
	}
	return 0;
}